
$(document).ready(function() {
    try {
        $(".sodao-dialog").boxy();
    }
    catch (err)
    { }
});

var sodaoBox = Boxy;
var loadingBox;
var dialogList = new Array();
var sodaoCheck = {
    _u: function() {
        for (var i = 0; i < arguments.length; i++)
            if (typeof arguments[i] != 'undefined') return false;
        return true;
    },
    _un: function() {
        var _tmp = arguments[0];
        if (_tmp == 'undefined' || _tmp == null)
            return true;
        return false;
    },
    _une: function() {
        var _tmp = arguments[0];
        if (_tmp == 'undefined' || _tmp == null || _tmp == '')
            return true;
        return false;
    },
    _nau: function() {
        var _uc = 0;
        for (var i = 0; i < arguments.length; i++) {
            if (typeof arguments[i] != 'undefined' && arguments[i] != null) { _uc++; }
        }
        return _uc < arguments.length ? true : false;
    },
    _gt0: function() {
        var _tmp = arguments[0];
        if (_tmp == 'undefined' || _tmp == null)
            return false;
        if (isNaN(_tmp)) { return false; }
        return _tmp > 0 ? true : false;
    },
    _gtN: function(_num, _min) {
        if (_num > _min) { return _num; }
        return _min;
    },
    _word: function(txtArea, tipId, maxRows, minRows) {
        var maxWords = parseInt($(txtArea).attr("maxlength"));
        var curWords = $(txtArea).val().length;
        if (curWords > maxWords) {
            $(txtArea).val($(txtArea).val().substring(0, maxWords));
            if (tipId != "") { $('#' + tipId).html(maxWords) };
        } else {
            if (tipId != "") { $('#' + tipId).html(curWords); };
        }
        if (maxRows) {
            var rows = $(txtArea).val().split('\n').length;
            if (rows > minRows) {
                if (rows > maxRows) { $(txtArea).attr('rows', maxRows); }
                else { $(txtArea).attr('rows', rows); }
            } else {
                $(txtArea).attr('rows', minRows);
            }
        }
    }
}
var sDialog = {
    //activePoint
    activeLevel: function(level, title, callback) {
        if (sodaoCheck._une(level) && sodaoCheck._une(title)) {
            return this.message('调用此函数，请设置text, title参数！', "调用错误提示", 3000);
        }
        var html = '<p>' + title + '</p><div class="tip-d-grade">用户等级 +' + level + '</div>';
        return this.activeBox(html, 1800, '', callback, "tip-d");
    },
    //activePoint
    activePoint: function(point, exp, title, callback) {
        if ((sodaoCheck._un(point) && sodaoCheck._un(exp)) || sodaoCheck._une(title)) {
            return this.message('调用此函数，请设置point, exp, title参数且point, exp至少一个不等于0！', "调用错误提示", 3000);
        }
        if (parseInt(point) == 0 && parseInt(exp) == 0) {
            return this.message('调用此函数，point, exp至少一个不等于0！', "调用错误提示", 3000);
        }
        var prefix = "+";
        if (parseInt(point) < 0 || parseInt(exp) < 0) { prefix = ""; }
        var html = '<p>' + title + '</p><div class="tip-d-integral">积分 <img src="http://css.sodao.com/dialog/ico-integral.png" width="16" height="16" /> ' + prefix + point + '</div>'
                + '<div class="tip-d-exp">经验 <img src="http://css.sodao.com/dialog/ico-experience.png" width="16" height="16" /> ' + prefix + exp + '</div>';
        return this.activeBox(html, 1800, '', callback, "tip-d");
    },
    //active message
    activeMsg: function(objId, msg, align, width, timeout, action, callback) {
        var obj, _objId;
        if (typeof objId == "object") {
            obj = $(objId);
            _objId = obj.attr('id');
        } else {
            obj = $('#' + objId);
            _objId = objId;
        }
        if (sodaoCheck._un(obj) && sodaoCheck._une(msg)) {
            return this.message('调用此函数，请设置objId, msg参数且objId必须存在！', "调用错误提示", 3000);
        }

        var html = $('#activeBox_' + _objId);
        if (!html.attr('id')) {
            var css;
            if (align == 'L') { css = 'tips-box-t'; }
            else if (align == 'T') { css = 'tips-box-b'; }
            else if (align == 'R') { css = 'tips-box-t'; }
            else { css = 'tips-box-l'; }
            var msg = '<span></span><div class="tips-content">' + msg + '</div>';
            html = this._getBox(_objId, msg, css);
            if (sodaoCheck._gt0(width)) { html.css({ width: width }); }
            html.appendTo(document.body);
        } else {
            html.find('.tips-content').html(msg);
            return false;
        }
        var xy = sDialog._getDialogXY(false, html.outerWidth(), objId, align);
        var left = xy.left, top = xy.top;

        if (align == 'W') {
            left = left + html.outerWidth() + 5; top = top - html.outerHeight();
            if (html.outerHeight() > obj.outerHeight()) { top += (html.outerHeight() - obj.outerHeight()) / 2; }
            else { top -= (html.outerHeight() - obj.outerHeight()) / 2; }
        } else if (align == 'T') {
            top = top - obj.outerHeight() - html.outerHeight();
        } else if (align == 'R') {
            left = left;
        }
        if (sodaoCheck._une(action) || action == "fade") {
            html.css({ left: left, top: top }).stop().fadeIn("slow", function() { sDialog._closeActive(_objId, timeout, callback); });
        } else if (action == "slide-L") {
            html.css({ left: (left - 60), top: top }).stop().animate({
                left: left, opacity: 'show'
            }, { duration: 500, complete: function() { sDialog._closeActive(_objId, timeout, callback); } });
        }
        else if (action == "slide-R") {
            html.css({ left: (left + 60), top: top }).stop().animate({
                left: left, opacity: 'show'
            }, { duration: 500, complete: function() { sDialog._closeActive(_objId, timeout, callback); } });
        }
        return false;
    },
    //close active msg
    activeClose: function(objId) {
        try {
            $('#activeBox_' + objId).stop().fadeOut("slow", function() { $('#activeBox_' + objId).remove(); });
        } catch (e) { }
    },
    //_close active
    _closeActive: function(objId, timeout, callback) {
        if (sodaoCheck._gt0(timeout)) {
            setTimeout(function() { sDialog.activeClose(objId); }, timeout);
        }
        if (callback) { callback(); }
    },
    //get div full content
    _getBox: function(objId, msg, cssName) {
        var html = $('<div></div>').attr("class", cssName).attr("id", "activeBox_" + objId).css({
            display: "none", position: "absolute",
            zIndex: sDialog.getZIndex(), opacity: 1.0
        }).append(msg);
        return html;
    },
    //activeBox
    activeBox: function(msg, timeout, action, callback, cssName) {
        if (!cssName) { cssName = ''; }
        var html = this._getBox('', msg, cssName);
        var v = sodaoBox._viewport();
        html.appendTo(document.body);
        var left = v.left + (v.width) / 2 - html.width() / 2;
        var top = v.top + (v.height) / 2 - html.height() / 2;
        var tarTop = top - 120;
        if (tarTop < 0) { tarTop = 0; }
        html.css({ left: left, top: top }).stop().animate({
            top: tarTop, opacity: 'show'
        }, { duration: 900, complete: function() { sDialog._closeActive('', timeout, callback); } });
        return false;
    },
    //loading
    loading: function(msg, timeout, width, height, modal) {
        if (sodaoCheck._un(msg)) {
            return this.message('调用此函数，请设置msg参数！', "调用错误提示", 3000);
        }
        if (msg == '') { msg = '数据载入中，请稍候...'; }
        if (sodaoCheck._un(width)) { width = 250; }
        //if (sodaoCheck._un(modal)) { modal = true; }
        var options = this._getOptions(width, height, modal);
        if (sodaoCheck._gt0(timeout)) { options = jQuery.extend(options, { closeDelay: sodaoCheck._gtN(timeout, 10000) }) }
        else { options = jQuery.extend(options, { closeDelay: 10000 }) };
        loadingBox = sodaoBox.loading(msg, options);
        return false;
    },
    //alert
    alert: function(msg, title, callback, cbData, btnText, modal) {
        if (sodaoCheck._une(msg)) {
            return this.message('调用此函数，请设置msg参数！', "调用错误提示", 3000);
        }
        var options = {};
        if (sodaoCheck._un(modal)) {
            options = jQuery.extend(options, { modal: true });
        } else {
            options = jQuery.extend(options, { modal: modal });
        }
        if (!sodaoCheck._un(title)) { options = jQuery.extend(options, { title: title }) };
        if (!sodaoCheck._un(cbData)) { options = jQuery.extend(options, { callbackData: cbData }) };
        sodaoBox.alert(msg, callback, options, btnText);
        return false;
    },
    //message
    message: function(msg, title, delay, width, height, X, Y) {
        if (sodaoCheck._une(msg) || sodaoCheck._un(title)) {
            sodaoBox.popTip("调用错误提示", '调用此函数，请设置msg,title参数！', 3000);
            return false;
        }
        this._msgbox(msg, title, '', delay, width, height, X, Y);
        return false;
    },
    //error
    error: function(msg, title, width, height) {
        if (sodaoCheck._une(msg) || sodaoCheck._un(title)) {
            sodaoBox.popTip("调用错误提示", '调用此函数，请设置msg,title参数！', 3000);
            return false;
        }
        this._msgbox(msg, title, 'Error', 0, width, height);
        return false;
    },
    //info
    info: function(msg, title, width, height, delay, closeCallback) {
        if (sodaoCheck._une(msg) || sodaoCheck._un(title)) {
            sodaoBox.popTip("调用错误提示", '调用此函数，请设置msg,title参数！', 3000);
            return false;
        }
        this._msgbox(msg, title, 'Info', delay, width, height, 0, 0, closeCallback);
        return false;
    },
    //msgbox
    _msgbox: function(msg, title, type, delay, width, height, X, Y, afterHideCallback) {
        if (sodaoCheck._une(msg) || sodaoCheck._un(title)) {
            sodaoBox.popTip("调用错误提示", '调用此函数，请设置msg,title参数！', 3000);
            return false;
        }
        var options = jQuery.extend({ imageType: type }, this._getOptions(width, height));
        if (sodaoCheck._gt0(delay)) { options = jQuery.extend(options, { closeDelay: delay }) };
        if (sodaoCheck._gt0(X)) { options = jQuery.extend(options, { x: X }) };
        if (sodaoCheck._gt0(Y)) { options = jQuery.extend(options, { y: Y }) };
        if (afterHideCallback) { options = jQuery.extend(options, { afterHide: afterHideCallback }) };
        sodaoBox.popTip(title, msg, 0, options);
        return false;
    },
    //confirm(callback无参数，回调确定后的函数）
    confirm: function(msg, callback, title, cbData) {
        if (sodaoCheck._une(msg) || sodaoCheck._un(callback)) {
            return this.message('调用此函数，请设置msg, callback参数！', "调用错误提示", 3000);
        }
        var options = { modal: true };
        if (!sodaoCheck._un(title)) { options = jQuery.extend(options, { title: title }) };
        if (!sodaoCheck._un(cbData)) { options = jQuery.extend(options, { callbackData: cbData }) };
        sodaoBox.confirm(msg, callback, options);
        return false;
    },
    //ask: answers数组，回调callback(返回选择的值)
    ask: function(question, answers, callback, cbData) {
        if (sodaoCheck._nau(question, answers, callback)) {
            return this.message('调用此函数，请设置question, answers, callback参数！', "调用错误提示", 3000);
        }
        var options = {};
        if (!sodaoCheck._un(cbData)) { options = jQuery.extend(options, { callbackData: cbData }) };
        sodaoBox.ask(question, answers, callback, options);
        return false;
    },
    //loadId
    loadId: function(id, title, width, height, modal, customerCallback, dependId, align) {
        if (sodaoCheck._une(id) || sodaoCheck._un(title)) {
            return this.message('调用此函数，请设置id, title参数！', "调用错误提示", 3000);
        }
        if (id.substring(0, 1) != '#') { id = '#' + id; }
        var _obj = $(id);
        if (!_obj.attr('id')) {
            return this.message('指定的ID=' + id.replace('#', '') + '的元素未找到，请检查！', "调用错误提示", 3000);
        }
        var options = jQuery.extend({ title: title }, this._getOptions(width, height, modal));
        if (customerCallback) { options = jQuery.extend(options, { customerClosed: customerCallback }); }
        var xy = this._getDialogXY(modal, width, dependId, align);
        if (xy.left && xy.left != 0 && xy.top != 0) {
            options = jQuery.extend(options, { center: false, x: xy.left, y: xy.top });
        }
        sodaoBox.popLinked(_obj, options);
        return false;
    },
    //load
    load: function(url, title, width, height, modal, showCallBack, customerCloseCallback, dependId, align, method, data) {
        if (sodaoCheck._une(url) || sodaoCheck._un(title)) {
            return this.message('调用此函数，请设置url, title参数！', "调用错误提示", 3000);
        }
        var options = jQuery.extend({ title: title }, this._getOptions(width, height, modal));
        if (showCallBack) { options = jQuery.extend(options, { afterShow: showCallBack }); }
        if (customerCloseCallback) { options = jQuery.extend(options, { customerClosed: customerCloseCallback }); }
        var xy = this._getDialogXY(modal, width, dependId, align);
        if (xy.left && xy.left != 0 && xy.top != 0) {
            options = jQuery.extend(options, { center: false, x: xy.left, y: xy.top });
        }
        sodaoBox.load(url, options, method, data);
        return false;
    },

    //loadForm 回调函数方法（action, formData, callback, source）
    loadForm: function(url, title, callback, width, height, modal, dependId, align) {
        if (sodaoCheck._une(url) || sodaoCheck._nau(title, callback)) {
            return this.message("调用此函数，请设置url, title, callback参数！");
        }
        var options = { title: title, onFormSubmit: callback }; //test submiting submiting: true
        options = jQuery.extend(options, this._getOptions(width, height, modal));
        var xy = this._getDialogXY(modal, width, dependId, align);
        if (xy.left && xy.left != 0 && xy.top != 0) {
            options = jQuery.extend(options, { center: false, x: xy.left, y: xy.top });
        }
        sodaoBox.load(url, options);
        return false;
    },
    //loadIFrame
    loadIFrame: function(url, title, width, height, modal, dependId, align, closeable, callBack, callBackOptions, redirectUrl) {
        if (sodaoCheck._une(url) || sodaoCheck._un(title)) {
            return this.message("调用此函数，请设置url, title参数！");
        }
        var options = jQuery.extend({ title: title }, this._getOptions(width, height, modal));
        var xy = this._getDialogXY(modal, width, dependId, align);
        if (xy.left && xy.left != 0 && xy.top != 0) {
            options = jQuery.extend(options, { center: false, x: xy.left, y: xy.top });
        }
        if (!sodaoCheck._un(closeable)) {
            if (!closeable) {
                options = jQuery.extend(options, { closeable: false });
            }
        }
        var _wid = Math.random();
        if (url.indexOf('?') != -1) { url += '&window=' + _wid; }
        else { url += '?window=' + _wid; }
        if (callBack) { url += '&_cb=' + callBack; }
        if (callBackOptions) { url += '&_cbo=' + encodeURIComponent(callBackOptions); }
        if (redirectUrl) { url += '&_rurl=' + encodeURIComponent(redirectUrl); }
        var dialog = sodaoBox.loadFrame(url, options);
        dialogList[_wid] = dialog;
        return false;
    },
    change: function(obj, title, content) {
        sodaoBox.get(obj).setTitle(title);
        var html = $("<div></div>").append(content);
        sodaoBox.get(obj).setContent(html);
        return false;
    },
    //针对Iframe窗口自动关闭问题
    closef: function(_wid) {
        if (dialogList[_wid]) {
            dialogList[_wid].hide();
        }
        return false;
    }, //关闭
    close: function(obj) {
        var _box = sodaoBox.get(obj);
        try {
            if (_box.options.customerClosed) {
                _box.hide();
                _box.options.customerClosed(obj);
                _box.unload();
                return false;
            }
        } catch (e) { if (_box) { _box.unload(); } return false; }

        try {
            _box.hideAndUnload();
        } catch (e) { }
        return false;
    },
    //hideLoading
    hideLoading: function() {
        try {
            loadingBox.hideAndUnload();
        } catch (e) { }
    },
    //return options
    _getOptions: function(width, height, modal) {
        var options = {};
        if (sodaoCheck._gt0(width)) { options = jQuery.extend(options, { width: sodaoCheck._gtN(width, 200) }) };
        if (sodaoCheck._gt0(height)) { options = jQuery.extend(options, { height: sodaoCheck._gtN(height, 50) }) };
        if (!sodaoCheck._un(modal)) { options = jQuery.extend(options, { modal: modal }) };
        return options;
    },
    //获取依赖的位置
    _getDialogXY: function(modal, width, dependId, align, bFixed) {
        if (modal || !dependId) { return [0, 0]; }
        var obj = typeof dependId == "object" ? $(dependId) : $('#' + dependId);
        if (sodaoCheck._un(obj) || !sodaoCheck._gt0(width)) {
            return [0, 0];
        }
        var xy = obj.offset();
        if (align == "R") {
            xy.top += obj.outerHeight();
            xy.left = xy.left + obj.outerWidth() - width;
        }
        else {
            xy.top += obj.outerHeight();
        }
        if (bFixed) {
            var sTop = $(document).scrollTop();
            var sLeft = $(document).scrollLeft();
            xy.top -= sTop;
            xy.left -= sLeft;
        }
        return xy;
    },
    showIFrameMask: function(dependId) {
        if (jQuery.browser.msie && jQuery.browser.version < 7) {
            var depDiv = $('#' + dependId);
            var iMask = $('#IframeMask_' + dependId);
            if (!iMask.attr("id")) {
                //iframe 遮罩
                iMask = jQuery('<iframe id="IframeMask_' + dependId + '" src="javascript:\'\';"></iframe>')
								.css({ position: 'absolute', zIndex: -1,
								    width: depDiv.width() + 3, height: depDiv.height() + 3, left: depDiv.position().left, top: depDiv.position().top
								}).appendTo(depDiv.parent());
            } else {
                iMask.css({ display: '', width: depDiv.width() + 3, height: depDiv.height() + 3, left: depDiv.position().left, top: depDiv.position().top });
            }
        }
    },
    hideIFrameMask: function(dependId) {
        var iMask = $('#IframeMask_' + dependId);
        if (iMask.attr("id")) {
            iMask.css("display", "none").remove();
        }
    },
    getZIndex: function() {
        this.zIndex++;
        return this.zIndex;
    },
    zIndex: 2024
}

/*
refresh:登录成功后是否刷新，若为true，则后面两个参数无效
callBack:回调函数 function(user,options) 其中user为登录成功后用户名，options为传入的附加参数，格式为JSON
strOptions:附加参数，符合JSON格式的字符串 "{param1:1,param2:2}"
*/
var SoDaoLogin = {
    callBack: null,
    refresh: false,
    check: function(refresh, callBack, strOptions) {
        if (!strOptions)
            strOptions = "";

        this.callBack = callBack;
        this.refresh = refresh;
        var visitUser = "";
        var ajax = {
            url: "/user/GetLoginInfo", type: "POST", dataType: "json", async: false,
            success: function(data, textStatus) {
                if (data.userName != null)
                    visitUser = data.userName;
            }
        };
        $.ajax(ajax);

        if (visitUser == "") {
            sDialog.loadIFrame("/User/LoginWindows?LoginWinFromUrl=" + encodeURIComponent(top.location.href), "搜道网 因为真实 所以精彩！赶快注册帐号登录，体验更多精彩乐趣！", 550, 230, true, null, "", true, "SoDaoLogin.loginCallback", strOptions, "http://www.sodao.com/user/loginCallback");
        }
        return visitUser;
    },
    loginCallback: function(_wid, _user, _options) {
        sDialog.closef(_wid);
        if (this.refresh == true) {
            location.reload();
            return;
        }
        if (this.callBack)
            this.callBack(_user, _options);
    }
};

/*删除评论，提示确认*/
var delConfirm = {
    delConfirmId: "divCmtDelConfirm",
    prevType: "",
    cmtOptions: {
        width: 110,
        clkObj: null,
        sourceId: "",
        cmtId: "",
        cmtMd: "",
        cmtType: "",
        cmtDelCallback: null,
        cmtUser: ""
    },
    dynOptions: {
        width: 110,
        dynObj: null,
        dynId: "",
        dynCallback: null,
        dynMd: ""
    },
    dynZoneOptions: {
        width: 110,
        dynObj: null,
        dynId: "",
        dynCallback: null,
        dynMd: "",
        zoneId: 0
    },
    comOptions: {
        width: 110,
        obj: null,
        options: null,
        callback: null,
        type: ""
    },
    //通用
    show: function(obj, width, delName, options, callback) {
        this.comOptions.obj = obj;
        this.comOptions.width = width;
        this.comOptions.options = options;
        this.comOptions.callback = callback;
        this.comOptions.type = delName;
        obj.blur();
        var container = this.getContainer(width, obj);
        if (container.html() != "" && this.comOptions.type == delName) { container.slideDown('fast'); return false; }
        else { container.html(""); }
        $('<a href="#"/>').append("确定删除" + delName).bind("click", function() {
            delConfirm.hide();
            if (delConfirm.comOptions.callback) { delConfirm.comOptions.callback(delConfirm.comOptions.obj, delConfirm.comOptions.options); }
            return false;
        }).appendTo(container);
        container.append("&nbsp;&nbsp;");
        $('<a href="#" style="color:#888"/>').append("取消").bind("click", function() {
            delConfirm.hide();
            return false;
        }).appendTo(container);
        container.slideDown('fast');
        this.prevType == "dyn";
        return false;
    },
    showDyn: function(obj, dynId, dynCall, dynMd) {
        this.dynOptions.dynObj = obj;
        this.dynOptions.dynId = dynId;
        this.dynOptions.dynCallback = dynCall;
        this.dynOptions.dynMd = dynMd;
        var width = 110;
        obj.blur();
        var container = this.getContainer(this.dynOptions.width, obj);
        if (container.html() != "" && this.prevType == "dyn") { container.slideDown('fast'); return false; }
        else { container.html(""); }
        $('<a href="#"/>').append("确定删除动态").bind("click", function() {
            delConfirm.hide();
            if (delConfirm.dynOptions.dynCallback) { delConfirm.dynOptions.dynCallback(delConfirm.dynOptions.dynObj, delConfirm.dynOptions.dynId, delConfirm.dynOptions.dynMd); }
            return false;
        }).appendTo(container);
        container.append("&nbsp;&nbsp;");
        $('<a href="#" style="color:#888"/>').append("取消").bind("click", function() {
            delConfirm.hide();
            return false;
        }).appendTo(container);
        container.slideDown('fast');
        this.prevType == "dyn";
        return false;
    }
    ,
    showZoneDyn: function(obj, dynId, zoneId, dynCall, dynMd) {
        this.dynZoneOptions.dynObj = obj;
        this.dynZoneOptions.dynId = dynId;
        this.dynZoneOptions.dynCallback = dynCall;
        this.dynZoneOptions.dynMd = dynMd;
        this.dynZoneOptions.zoneId = zoneId;

        var width = 110;
        obj.blur();
        var container = this.getContainer(this.dynZoneOptions.width, obj);
        if (container.html() != "" && this.prevType == "dyn") { container.slideDown('fast'); return false; }
        else { container.html(""); }
        $('<a href="#"/>').append("确定删除动态").bind("click", function() {
            delConfirm.hide();
            if (delConfirm.dynZoneOptions.dynCallback) { delConfirm.dynZoneOptions.dynCallback(delConfirm.dynZoneOptions.dynObj, delConfirm.dynZoneOptions.dynId, delConfirm.dynZoneOptions.zoneId, delConfirm.dynZoneOptions.dynMd); }
            return false;
        }).appendTo(container);
        container.append("&nbsp;&nbsp;");
        $('<a href="#" style="color:#888"/>').append("取消").bind("click", function() {
            delConfirm.hide();
            return false;
        }).appendTo(container);
        container.slideDown('fast');
        this.prevType == "dyn";
        return false;
    },
    showCmt: function(obj, sourceId, cmtId, md, cmtType, doCallback, cmtUser) {
        this.cmtOptions.clkObj = obj;
        this.cmtOptions.sourceId = sourceId;
        this.cmtOptions.cmtId = cmtId;
        this.cmtOptions.cmtMd = md;
        this.cmtOptions.cmtType = cmtType;
        this.cmtOptions.cmtDelCallback = doCallback;
        this.cmtOptions.cmtUser = cmtUser;
        var width = 110;
        obj.blur();
        var container = this.getContainer(this.cmtOptions.width, obj);
        if (container.html() != "" && this.prevType == "cmt") { container.slideDown('fast'); return false; }
        else { container.html(""); }

        $('<a href="#"/>').append("确定删除回复").bind("click", function() {
            delConfirm.hide();
            SoDaoComment.deleteComment(delConfirm.cmtOptions.clkObj, delConfirm.cmtOptions.sourceId, delConfirm.cmtOptions.cmtId, delConfirm.cmtOptions.cmtMd, delConfirm.cmtOptions.cmtType, delConfirm.cmtOptions.cmtUser);
            if (delConfirm.cmtOptions.cmtDelCallback) { delConfirm.cmtOptions.cmtDelCallback(); }
            return false;
        }).appendTo(container);
        container.append("&nbsp;&nbsp;");
        $('<a href="#" style="color:#888"/>').append("取消").bind("click", function() {
            delConfirm.hide();
            return false;
        }).appendTo(container);
        container.slideDown('fast');
        this.prevType == "cmt";
        return false;
    },
    getContainer: function(width, obj) {
        var xy = sDialog._getDialogXY(false, width, obj, 'L');
        var container = $('#' + this.delConfirmId);
        if (container.attr('id')) {
            container.css({ zIndex: sDialog.getZIndex(), left: xy.left, top: xy.top });
        } else {
            container = $("<div></div>").attr("id", this.delConfirmId).css({ zIndex: sDialog.getZIndex(), textAlign: "center", position: "absolute", background: "#fff", display: "none", width: width, left: xy.left, top: xy.top, border: "1px solid #888", padding: "4px 2px 3px 2px" });
            container.bind("mouseleave", function() {
                delConfirm.hide();
            }).appendTo(document.body);
        }
        return container;
    },
    hide: function() {
        $('#' + this.delConfirmId).fadeOut("fast");
    }
}

/*送礼弹窗*/
var SoDaoGift = {

    show: function(userName, win, opt) {
        var url = "/home/gift/giftwin?u=" + userName;
        var gotoclosepar = "?u=" + userName;
        if (opt) {
            if (opt.sendMode) {
                if (opt.sendMode != "") {
                    url += "&sendmode=" + opt.sendMode;
                    gotoclosepar += "&sendmode=" + opt.sendMode;
                }
            }

            if (opt.sendType) {
                if (opt.sendType != "") {
                    url += "&sendType=" + opt.sendType;
                    gotoclosepar += "&sendType=" + opt.sendType;
                }
            }

            if (opt.sendTime) {
                if (opt.sendTime != "") {
                    url += "&sendTime=" + opt.sendTime;
                    gotoclosepar += "&sendTime=" + opt.sendTime;
                }
            }

            if (opt.gt_id) {
                if (opt.gt_id != "") {
                    url += "&gt_id=" + opt.gt_id;
                    gotoclosepar += "&gtid=" + opt.gt_id;

                }
            }

            if (opt.message) {
                if (opt.message != "") {
                    url += "&message=" + escape(opt.message);
                    gotoclosepar += "&message=" + escape(opt.message);
                }
            }

            if (opt.typeId) {
                if (opt.typeId != "") {
                    url += "&typeId=" + opt.typeId;
                    gotoclosepar += "&typeId=" + opt.typeId;
                }
            }

            if (opt.cateId) {
                if (opt.cateId != "") {
                    url += "&cateId=" + opt.cateId;
                    gotoclosepar += "&cateId=" + opt.cateId;
                }
            }



            if (opt.birthdaySend) {
                if (opt.birthdaySend != "") {
                    url += "&birthdaySend=" + opt.birthdaySend;
                    gotoclosepar += "&birthdaySend=" + opt.birthdaySend;
                }
            }
            if (opt.winId && opt.gift == "show") {
                if (opt.winId != "") {
                    url += "&window=" + opt.winId;
                    gotoclosepar += "&wid=" + opt.winId;
                }
            }

            if (opt.gift) {
                if (opt.gift != "") {
                    url += "&gift=" + opt.gift;
                    gotoclosepar += "&gift=" + opt.gift;
                }
            }

            if (opt.refurl) {
                if (opt.refurl != "") {
                    url += "&refurl=" + opt.refurl;
                    gotoclosepar += "&refurl=" + opt.refurl;
                }
            }

        }

        if (opt && opt.gift == "show") {

            SoDaoGift.gotoclose(opt.refurl, gotoclosepar + "&sendurl=http://i.sodao.com/home/gift/giftwin&operate=gold", "iframe1");
            // location.href = url;
        } else {

            if (win) {
                win.sDialog.loadIFrame(url, "送礼", 600, 440, true);
            }
            else {

                sDialog.loadIFrame("/home/gift/giftwin?u=" + userName, "送礼", 600, 440, true);
            }
        }

        return false;

    }
    ,
    showThx: function(userName) {
        sDialog.loadIFrame("/home/gift/thxbox?u=" + userName, "答谢", 630, 490, true); return false;
    },
    showThx1: function(userName, giftId) {
        sDialog.loadIFrame("/home/gift/thxbox?u=" + userName + "&gt_id=" + giftId, "答谢", 630, 490, true); return false;
    },
    showForMM: function(userName) {
        sDialog.loadIFrame("/home/gift/giftwin?mm=1&u=" + userName, "送礼", 600, 440, true); return false;
    },
    sendGift: function(userName, giftId, wishId, gb_id, win, opt) {
        var url = "/Home/Gift/DialogSend?gt_id=" + giftId;
        if (userName) {
            if (userName != "") {
                url += "&u=" + userName;
            }
        }

        if (wishId) {
            if (wishId != "") {
                url += "&wishid=" + wishId;
            }
        }

        if (gb_id) {
            if (gb_id != "") {
                url += "&gb_id=" + gb_id;
            }
        }

        if (opt) {
            if (opt.sendMode) {
                if (opt.sendMode != "") {
                    url += "&sendmode=" + opt.sendMode;
                }
            }

            if (opt.sendType) {
                if (opt.sendType != "") {
                    url += "&sendType=" + opt.sendType;
                }
            }

            if (opt.sendTime) {
                if (opt.sendTime != "") {
                    url += "&sendTime=" + opt.sendTime;
                }
            }

            if (opt.giftNum) {
                if (opt.giftNum != "") {
                    url += "&giftNum=" + escape(opt.giftNum);
                }
            }

            if (opt.message) {
                if (opt.message != "") {
                    url += "&message=" + escape(opt.message);
                }
            }
        }


        if (win) {
            win.sDialog.loadIFrame(url, "送礼", 420, 475, true);
        }
        else {
            //sDialog.load(url, "送礼", 480, 485, true); return false;
            sDialog.loadIFrame(url, "送礼", 420, 475, true);
        }

        return false;
    },
    showGiftPay: function(win, obj) {

        var url = "/Gift/GiftPay?gt_id=" + obj.gt_id + "&u=" + obj.userName;
        var gotoclosepar = "?gtid=" + obj.gt_id + "&u=" + obj.userName;
        if (obj.wish_id) {
            url += "&wish_id=" + obj.wish_id;
            gotoclosepar += "&wish_id=" + obj.wish_id;
        }

        if (obj.gb_id) {
            url += "&gb_id=" + obj.gb_id;
            gotoclosepar += "&gb_id=" + obj.gb_id;
        }

        if (obj.sendTime) {
            url += "&sendTime=" + obj.sendTime;
            gotoclosepar += "&sendTime=" + obj.sendTime;
        }

        if (obj.sendMode) {
            url += "&sendMode=" + obj.sendMode;
            gotoclosepar += "&sendMode=" + obj.sendMode;
        }

        if (obj.sendType) {
            url += "&sendType=" + obj.sendType;
            gotoclosepar += "&sendType=" + obj.sendType;
        }

        if (obj.prePage) {
            url += "&prePage=" + obj.prePage;
            gotoclosepar += "&prePage=" + obj.prePage;

        }

        if (obj.message) {
            url += "&message=" + escape(obj.message);
            gotoclosepar += "&message=" + escape(obj.message);
        }

        if (obj.typeId) {
            url += "&typeId=" + obj.typeId;
            gotoclosepar += "&typeId=" + obj.typeId;
        }

        if (obj.cateId) {
            url += "&cateId=" + obj.cateId;
            gotoclosepar += "&cateId=" + obj.cateId;
        }
        if (obj.giftNum) {
            url += "&giftNum=" + obj.giftNum;
            gotoclosepar += "&giftNum=" + obj.giftNum;
        }

        if (obj.birthdaySend) {
            url += "&birthdaySend=" + obj.birthdaySend;
            gotoclosepar += "&birthdaySend=" + obj.birthdaySend;

        }

        if (obj.gift) {
            url += "&gift=" + obj.gift;
            gotoclosepar += "&gift=" + obj.gift;

        }

        if (obj.window && obj.gift == "show") {

            url += "&window=" + obj.window;
            gotoclosepar += "&wid=" + obj.window;
        }

        if (obj.refurl) {
            url += "&refurl=" + obj.refurl;
            gotoclosepar += "&refurl=" + obj.refurl;
        }

        if (obj.gift == "show") {

            SoDaoGift.gotoclose(obj.refurl, gotoclosepar + "&sendurl=http://i.sodao.com/Gift/GiftPay&operate=pay", "iframe1");
            //  location.href = url;
        } else {
            win.sDialog.loadIFrame(url, "礼物支付", 480, 430, true);

        }
        return false;
    },
    showWish: function(para) {
        sDialog.loadIFrame("/Home/Gift/WishReason?gt_id=" + para.gt_id + "&u=" + para.userName, "礼物许愿", 410, 450, true);
        return false;
    },
    showWinWish: function(para) {
        var title = para.title ? para.title : "礼物许愿";
        sDialog.loadIFrame("/Home/Gift/WishWinReason?u=" + para.userName, title, 600, 420, true);
        return false;
    },
    gotoclose: function(url, par, divid) {


        var iframe = "<IFRAME id='iframehtml' name='iframehtml' src='" + url + par + "' frameBorder='0' width='0' height='0' scrolling='auto'><\/IFRAME>";
        $("#" + divid).html(iframe);
         
    },
    gotoclosef: function(refurl, wid, operate) {

        var gotoclosepar = "?wid=" + wid + "&operate=" + operate;

        SoDaoGift.gotoclose(refurl, gotoclosepar, "iframe1");
    }

};



var SoDaoMessage = {
    /************************
    * *功能描述：发送消息给指定用户调用接口 from:发送人，mdFrom:发送人校验码，to:接收人，mdTo:接收人校验码，refurl:调用所在域的关闭窗口页面
    * *refurl页面内容：<script>parent.sDialog.closef('window');</script>，其中window为页面参数
    ************************/
    sendMessage: function(from, mdFrom, to, mdTo, refUrl) {
        $.ajax({
            url: "http://www.sodao.com/home/message/checkissendmessage?jsonp=?",
            type: "GET",
            dataType: "jsonp",
            data: { "tousername": to },
            success: function(data) {
                if (data.status == 0) {
                    var params = "from=" + from + "&mdfrom=" + mdFrom + "&to=" + to + "&mdto=" + mdTo + "&refurl=" + refUrl + "&rnd=" + Math.random();
                    sDialog.loadIFrame("http://www.sodao.com/home/message/sendmsg?" + params, "发送消息", 450, 340);
                }
                //要留言的人在我的黑名单里
                else if (data.status == -8) {
                    var url = "/friend/FriendOutWin?type=3&fromusername=" + from + "&tousername=" + to;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
                //要留言的人把我加为黑名单
                else if (data.status == -9) {
                    var url = "/friend/FriendOutWin?type=4&fromusername=" + from + "&tousername=" + to;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                } //彼此未有粉丝关系
                else if (data.status == -10) {
                    sDialog.info("哎呀，你们之间还没有相互关注呢！", "温馨提示", 100, 50, 5000);
                }
            }
        });
    },
    sendMessage2: function(from, mdFrom, to, mdTo, refUrl) {
        $.ajax({
            url: "/friend/IsFriendOutExist",
            type: "GET",
            dataType: "json",
            data: { "tousername": to },
            success: function(data) {
                if (data.state == 0) {
                    var params = "from=" + from + "&mdfrom=" + mdFrom + "&to=" + to + "&mdto=" + mdTo + "&refurl=" + refUrl + "&rnd=" + Math.random();
                    sDialog.loadIFrame("http://app.sodao.com/beautyclockdesktop/sendmsg?" + params, "发送消息", 450, 340);
                }
                //要留言的人在我的黑名单里
                else if (data.status == -8) {
                    var url = "/friend/FriendOutWin?type=3&fromusername=" + from + "&tousername=" + to;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
                //要留言的人把我加为黑名单
                else if (data.status == -9) {
                    var url = "/friend/FriendOutWin?type=4&fromusername=" + from + "&tousername=" + to;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
            }
        });
    }
};


var ZoneInvitedMessage = {
    /*加入专区成为专区成员*/
    ApplicationTrueMember: function(zid, zname, gid, code) {
        var url = "/home/message/ApplicationTrueMember?zid=" + zid + "&zname=" + zname + "&gid=" + gid + "&code=" + code;
        sDialog.load(url, '专区邀请', 0, 0, true, function() { getRequestList(1) }, "fade");
    }
};




/*添加好友请求(添加/同意/忽略)*/
var FriendRequestAdd = {
    /*请求加为好友 [callback]*/
    callBack: null,
    /*添加好友请求*/
    show: function(toUserName, model, callback, relation) {
        this.callBack = callback;

        var q2 = relation == null ? "" : "&relation=" + relation;
        $.ajax({
            url: "/friend/IsFriendOutExist",
            type: "GET",
            dataType: "json",
            data: { "tousername": toUserName },
            success: function(data) {
                if (data.status == 0) {
                    sDialog.load("/home/friend/add?tun=" + toUserName + q2, "请求加为好友", 430, 330, model); return false;
                }

                //要加好友的人在我的黑名单里
                else if (data.status == -8) {
                    var url = "/friend/FriendOutWin?type=3&tousername=" + toUserName;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
                //要加好友的人把我加为黑名单
                else if (data.state == -9) {
                    var url = "/friend/FriendOutWin?type=4&tousername=" + toUserName;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
            }
        });
    },
    /*同意好友请求对话框*/
    agree: function(fromUserName, requestcode, model, callback) {
        this.callBack = callback;
        sDialog.load("/home/friend/Process?fun=" + fromUserName + "&rc=" + requestcode, "添加到分组", 430, 330, model); return false;
    },
    /*取消好友请求*/
    cancel: function(fromUserName, requestcode, callback) {
        this.callBack = callback;
        var ajax = {
            url: "/ajax/FriendRequestOpera", type: "POST", dataType: "json",
            data: { fun: fromUserName, rc: requestcode, t: 2 },
            success: function(data) {
                switch (data.state) {
                    case 1:
                        FriendRequestAdd.doCallBack();
                        break;
                    default:
                        sDialog.message(data.msg, "提示", 1500, 180);
                        break;
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
            }
        };
        $.ajax(ajax);
    },
    /*添加关注*/
    concern: function(toUserName, model, callback, showCallback) {
        $.ajax({
            url: "http://www.sodao.com/home/friend/IsFriendOutExist?jsonp=?",
            type: "GET",
            dataType: "jsonp",
            data: { "tousername": toUserName },
            success: function(data) {
                if (data.status == 0) {
                    this.callBack = callback;
                    sDialog.load("/home/friend/ConcernAdd?cun=" + toUserName, "提示", 430, 100, model, showCallback); return false;
                }
                //要关注的人在我的黑名单里
                else if (data.status == -8) {
                    sDialog.hideLoading();
                    var url = "/friend/FriendOutWin?type=3&tousername=" + toUserName;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
                //要关注的人把我加为黑名单
                else if (data.status == -9) {
                    sDialog.hideLoading();
                    var url = "/friend/FriendOutWin?type=4&tousername=" + toUserName;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
            }
        });
    },
    /*添加关注2*/
    concern2: function(toUserName, model, callback, showCallback) {
        $.ajax({
            url: "http://www.sodao.com/home/friend/IsFriendOutExist?jsonp=?",
            type: "GET",
            dataType: "jsonp",
            data: { "tousername": toUserName },
            success: function(data) {
                if (data.status == 0) {
                    sDialog.load("/home/friend/ConcernAdd?cun=" + toUserName, "提示", 430, 100, model, showCallback, callback); return false;
                }
                //要关注的人在我的黑名单里
                else if (data.status == -8) {
                    sDialog.hideLoading();
                    var url = "/friend/FriendOutWin?type=3&tousername=" + toUserName;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
                //要关注的人把我加为黑名单
                else if (data.status == -9) {
                    sDialog.hideLoading();
                    var url = "/friend/FriendOutWin?type=4&tousername=" + toUserName;
                    sDialog.loadIFrame(url, "温馨提示", 410, 100, true);
                }
            }
        });
    },
    /*添加关注3 http://app.sodao.com/beautyclockdesktop*/
    concern3: function(toUserName, model, callback, showCallback) {
        sDialog.load("/beautyclockdesktop/ConcernAdd?cun=" + toUserName, "提示", 430, 100, model, showCallback, callback); return false;
    },
    doCallBack: function() {
        if (this.callBack) { this.callBack(); }
    }
}
//表情选择
var SoDaoExpressionBox = {
    /****************************
    **描述：初始化表情选择 input:录入框的jquery对象（必须为input类型）
    ***************************/
    init: function(input, faceCallback, objmsg) {
        if ($("#expression_box").length == 1) {
            this.doInit(input, faceCallback, objmsg);
        }
        else {
            $.get('/Utility/ExpressionBox', function(d) {
                $("body").append(d);
                $("#expression_box").css("zIndex", 1000);
                SoDaoExpressionBox.doInit(input, faceCallback, objmsg);
            });
        }
    },
    copyTo: function(targetId) {
        var expBox = $('#expression_box').clone();
        $('#' + targetId).html(expBox.html);
    },
    doInit: function(input, faceCallback, objmsg) {
        var expBar = $("<div class='comment-expression'></div>");
        for (var i = 1; i <= 7; i++) {
            var expA = $("<a href='#'></a>");
            var expImg = $("<img src='" + "http://css.sodao.com/home/img/expr" + i + ".png' width='24' height='24' />");
            expImg.appendTo(expA);
            expA.bind("click", i, function(event) { SoDaoExpressionBox.inputClickFace(event.data, input); if (faceCallback) { faceCallback('(:' + event.data + ')') }; return false; });
            expA.appendTo(expBar);
        }
        var expDown = $("<a href='#' class='sel-down'/>");
        expDown.appendTo(expBar);
        if (objmsg == null) {
            expBar.insertAfter(input);
        }
        else {
            objmsg.prepend(expBar);
        }
        expDown.click(function() {
            var expBox = $('#expression_box').clone();
            var ooffset = $(this).offset();
            expBox.appendTo('body');
            expBox.css('top', ooffset.top - 10);
            expBox.css('left', ooffset.left - 200);
            expBox.css("zIndex", 1000);
            expBox.show();
            expBox.bind("mouseleave", function() { $(this).remove(); });
            $("td a", expBox).each(function() {
                var re = /\/(\d+).gif/ig;
                var o = $('img', $(this));
                if (o.length == 0)
                    return;
                var str = o.attr('src');
                var arr = str.match(re);
                var n = RegExp.$1;
                $(this).attr("href", "#").bind("click", function() { SoDaoExpressionBox.inputClickFace(n, input, expBox); if (faceCallback) { faceCallback('(:' + n + ')') }; return false; });
            });
            return false;
        });
    },
    inputClickFace: function(i, input, expBox) {
        input.val(input.val() + '(:' + i + ')');
        if (expBox)
            expBox.remove();
        input.focus();
    },
    initNoHeader: function(input, faceCallback) {

        $.get('/Utility/ExpressionBox', function(d) {
            $("body").append(d);
            $("#expression_box").css("zIndex", 1000);
            SoDaoExpressionBox.doInitNoHeader(input, faceCallback);
        });

    },
    doInitNoHeader: function(input, faceCallback) {
        var expBar = $("<div class='comment-expression'></div>");
        var expDown = $("<a href='#'  class='face'/>");
        expDown.appendTo(expBar);
        expBar.insertAfter($("#show_gift"));

        expDown.click(function() {
            var expBox = $('#expression_box').clone();
            var ooffset = $(this).offset();
            expBox.appendTo('body');
            expBox.css('top', ooffset.top - 10);
            expBox.css('left', ooffset.left - 100);
            expBox.css("zIndex", 1000);
            expBox.show();
            expBox.bind("mouseleave", function() { $(this).remove(); });
            $("td a", expBox).each(function() {
                var re = /\/(\d+).gif/ig;
                var o = $('img', $(this));
                if (o.length == 0)
                    return;
                var str = o.attr('src');
                var arr = str.match(re);
                var n = RegExp.$1;
                $(this).attr("href", "#").bind("click", function() { SoDaoExpressionBox.inputClickFace(n, input, expBox); if (faceCallback) { faceCallback('(:' + n + ')') }; return false; });
            });
            return false;
        });
    }
}

function ap_stopAll(id) {
}
function getPlayerObject(type, src) {
    switch (type) {
        case 1:
            return '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" align="middle" width="450" height="374">'
                + '<param name="movie" value="' + src + '" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="never" /><param name="quality" value="high" /><param name="wmode" value="transparent" />'
                + '<embed height="374" width="450" '
                + 'allowscriptaccess="never" wmode="transparent" allowfullscreen="true" '
                + 'type="application/x-shockwave-flash" src="' + src + '"></embed></object><a title="收起该视频" class="videoClose" href="#">收起该视频</a>';
        case 2:
            return '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" align="middle" width="290" height="40">'
                + '<param name="movie" value="/flash/mp3player.swf?soundFile=' + src + '&autostart=yes" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="never" /><param name="quality" value="high" /><param name="wmode" value="transparent" />'
                + '<param name="flashvars" value="songUrl=' + src + '&autostart=yes&skin=0" />'
                + '<embed width="290" height="40" src="/flash/mp3player.swf?soundFile=' + src + '&autostart=yes" name="mp3player" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer"'
                + ' type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="never" quality="high"'
                + ' flashVars="songUrl=' + src + '&autoPlay=true&skin=0"></embed></object>';
        case 3:
            return '<object height="68" border="0" align="baseline" width="355" type="application/x-oleobject"'
                + 'standby="Loading Microsoft Windows Media Player components..."'
                + 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"'
                + 'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="wmaPlayer">'
                + '<param value="0" name="invokeURLs"/>'
                + '<param value="' + src + '" name="FileName"/>'
                + '<param value="1" name="ShowControls"/>'
                + '<param value="0" name="ShowPositionControls"/>'
                + '<param value="1" name="ShowAudioControls"/>'
                + '<param value="1" name="ShowTracker"/>'
                + '<param value="0" name="ShowDisplay"/>'
                + '<param value="1" name="ShowStatusBar"/>'
                + '<param value="0" name="AutoSize"/>'
                + '<param value="0" name="ShowGotoBar"/>'
                + '<param value="0" name="ShowCaptioning"/>'
                + '<param value="1" name="AutoStart"/>'
                + '<param value="0" name="PlayCount"/>'
                + '<param value="0" name="AnimationAtStart"/>'
                + '<param value="0" name="TransparentAtStart"/>'
                + '<param value="0" name="AllowScan"/>'
                + '<param value="1" name="EnableContextMenu"/>'
                + '<param value="0" name="ClickToPlay"/>'
                + '<param value="datawindow" name="DefaultFrame"/>'
                + '<embed height="68" border="0" align="baseline" width="335" invokeurls="0" defaultframe="datawindow" clicktoplay="0" enablecontextmenu="1"'
                + ' allowscan="1" transparentatstart="0" animationatstart="0" autorewind="0" autostart="1" showcaptioning="0" showgotobar="0" autosize="0"'
                + ' showstatusbar="1" showdisplay="0" showtracker="1" showaudiocontrols="1" showpositioncontrols="0" showcontrols="1" name="MediaPlayer"'
                + ' pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;"'
                + ' type="application/x-mplayer2" src="' + src + '"/>'
                + '</object>';
        default:
            return null;
    }
}
function getPlayerObject2(type, src) {
    switch (type) {
        case 1:
            return '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" align="middle" width="450" height="374">'
                + '<param name="movie" value="' + src + '" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="never" /><param name="quality" value="high" /><param name="wmode" value="transparent" />'
                + '<embed height="374" width="450" '
                + 'allowscriptaccess="never" wmode="transparent" allowfullscreen="true" '
                + 'type="application/x-shockwave-flash" src="' + src + '"></embed></object><a title="收起该视频" class="videoClose" href="#">收起该视频</a>';
        case 2:
            return '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" align="middle" width="290" height="40">'
                + '<param name="movie" value="/flash/mp3player.swf?soundFile=' + src + '&autostart=yes" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="never" /><param name="quality" value="high" /><param name="wmode" value="transparent" />'
                + '<param name="flashvars" value="songUrl=' + src + '&autostart=yes&skin=0" />'
                + '<embed width="290" height="40" src="/flash/mp3player.swf?soundFile=' + src + '&autostart=yes" name="mp3player" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer"'
                + ' type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="never" quality="high"'
                + ' flashVars="songUrl=' + src + '&autoPlay=true&skin=0"></embed></object>';
        case 3:
            return '<object height="374" border="0" align="baseline" width="450" type="application/x-oleobject"'
                + 'standby="Loading Microsoft Windows Media Player components..."'
                + 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"'
                + 'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="wmaPlayer">'
                + '<param value="0" name="invokeURLs"/>'
                + '<param value="' + src + '" name="FileName"/>'
                + '<param value="1" name="ShowControls"/>'
                + '<param value="0" name="ShowPositionControls"/>'
                + '<param value="1" name="ShowAudioControls"/>'
                + '<param value="1" name="ShowTracker"/>'
                + '<param value="0" name="ShowDisplay"/>'
                + '<param value="1" name="ShowStatusBar"/>'
                + '<param value="0" name="AutoSize"/>'
                + '<param value="0" name="ShowGotoBar"/>'
                + '<param value="0" name="ShowCaptioning"/>'
                + '<param value="1" name="AutoStart"/>'
                + '<param value="0" name="PlayCount"/>'
                + '<param value="0" name="AnimationAtStart"/>'
                + '<param value="0" name="TransparentAtStart"/>'
                + '<param value="0" name="AllowScan"/>'
                + '<param value="1" name="EnableContextMenu"/>'
                + '<param value="0" name="ClickToPlay"/>'
                + '<param value="datawindow" name="DefaultFrame"/>'
                + '<embed height="374" border="0" align="baseline" width="450" invokeurls="0" defaultframe="datawindow" clicktoplay="0" enablecontextmenu="1"'
                + ' allowscan="1" transparentatstart="0" animationatstart="0" autorewind="0" autostart="1" showcaptioning="0" showgotobar="0" autosize="0"'
                + ' showstatusbar="1" showdisplay="0" showtracker="1" showaudiocontrols="1" showpositioncontrols="0" showcontrols="1" name="MediaPlayer"'
                + ' pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;"'
                + ' type="application/x-mplayer2" src="' + src + '"/>'
                + '</object>';
        default:
            return null;
    }
}
function clickshare(sc, md) {
    var ajax = {
        url: "/share/ClickShare", type: "POST", dataType: "json",
        data: { sc: sc, md: md },
        success: function(data) { },
        error: function(XMLHttpRequest, textStatus, errorThrown) { }
    };
    $.ajax(ajax);
}
function playshare(obj, type, src, from) {
    if (type == 2 || type == 3)
        $(obj).parent().html(getPlayerObject(type, src));
    else {
        $(obj).parent().hide();
        var playerHolder = $(obj).parent().parent().find(".video-player");
        playerHolder.html(getPlayerObject(type, src));
        playerHolder.find("a").click(function() {
            if (from == "dyn") {
                $(this).parent().parent().parent().find(".video-thumbnail").show();
            } else {
                $(this).parent().parent().find(".video-thumbnail").show();
            }
            $(this).parent().html("");
            return false;
        });
        playerHolder.show();
    }
}
function playshare2(obj, type, src, from) {
    if (type == 2 || type == 3)
        $(obj).parent().html(getPlayerObject2(type, src));
    else {
        $(obj).parent().parent().hide();
        var playerHolder = $(obj).parent().parent().parent().find(".video-player");
        var hideHolder = "<a class=\"videoClose\" href=\"javascript:void(0)\" title=\"收起该视频\">收起该视频</a>";
        playerHolder.html(getPlayerObject2(type, src) + hideHolder);
        playerHolder.find("a").click(function() {
            if (from == "dyn") {
                $(this).parent().parent().find(".video-preview").show();
            } else {
                $(this).parent().parent().find(".video-thumbnail").show();
            }
            $(this).parent().html("");
            return false;
        });
        playerHolder.show();
    }
}
function reshareclose(rtnObj, id) {
    if ($(rtnObj).val() == "1") {
        var sp = $("#shareNum_" + id);
        sp.text(parseInt(sp.text()) + 1);
    }
}

//获取用户在线状态值；
function getUserStatus(user, callback) {
    $.getJSON(
        "http://status.sodao.com/status/callback/" + user + "?format=json&jsoncallback=?",
         function(json) {
             var timeText = "";
             if (json.s == "online") {
                 //var date1 = new Date(json.t.toDate("yyyy/MM/dd HH:mm:ss"));
                 var now = new Date();
                 var secs = parseInt((now.getTime() - json.t/*date1.getTime()*/) / 1000);

                 if (secs > 3600) {
                     timeText = parseInt(secs / 3600) + "小时前";
                 } else if (secs > 60) {
                     timeText = parseInt(secs / 60) + "分钟前";
                 } else {
                     if (secs <= 0) {
                         secs = 1;
                     }
                     timeText = secs + "秒前";
                 }
             }
             if (callback) {
                 callback(timeText, json);
             }
         }
    );
}
/*
描述：批量获取用户在线状态值；
user:用户名列表；sodao,sodao1,sodao2   ....
callback:回调函数
返回json数组，item: u [用户名] ,t [时间] ,p [所在位置]
*/
function batchGetUserStatus(user, callback) {
    $.getJSON(
        "http://status.sodao.com/status/batch?users=" + user + "&jsoncallback=?",
         function(jsonData) {
             if (jsonData != '') {
                 if (callback) {
                     callback(jsonData);
                 }
             }
         }
    );
}

/*
用户举报
*/
var UReport = {
    report: function(type, sourId, user, refer) {
        var refUrl = document.URL;
        if (!sodaoCheck._un(refer)) {
            refUrl = refer;
        }
        var form = $('<form target="_blank" method="post" action="/user/report"></form>').css("display", "none").appendTo(document.body);
        $('<input type="hidden" name="type" />').val(type).appendTo(form);
        $('<input type="hidden" name="source" />').val(sourId).appendTo(form);
        $('<input type="hidden" name="user" />').val(user).appendTo(form);
        $('<input type="hidden" name="refer" />').val(refUrl).appendTo(form);
        form.submit();
        return false;
    }
}

/*
用户搜索提示
*/
var SoDaoSearch = {
    dependId: "",
    dependObj: null,
    inputId: "",
    inputObj: null,
    prevKey: "",
    sending: false,
    rowIndex: -1,
    timerId: 0,
    tempKey: "",
    init: function(_depId, _inputId) {
        $(document).bind("click", SoDaoSearch.hiddenTips).bind("keydown", SoDaoSearch.keyDown);
        this.dependId = _depId;
        this.inputId = _inputId;
        this.dependObj = $('#' + _depId);
        this.inputObj = $('#' + _inputId);
    },
    startDetect: function() {
        if (this.timerId == 0) {
            this.timerId = window.setInterval("SoDaoSearch.detectInput();", 500);
        }
    },
    stopDetect: function() {
        if (this.timerId != 0) {
            window.clearInterval(this.timerId);
            this.timerId = 0;
        }
    },
    detectInput: function() {
        if (!this.inputObj && this.inputId != "") {
            this.inputObj = $('#' + this.inputId);
        }
        if (this.inputObj) {
            var curValue = this.inputObj.val();
            if (curValue != "" && this.prevKey != curValue && !this.sending) {
                this.sending = true;
                var ajax = {
                    url: '/ajax/websearch/tips', data: { kw: curValue }, type: 'GET', dataType: 'json', cache: false,
                    success: function(json, statusText) {
                        SoDaoSearch.prevKey = curValue;
                        SoDaoSearch.showTips(json);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        this.sending = false;
                    }
                };
                $.ajax(ajax);
            } else if (curValue == "") {
                SoDaoSearch.hiddenTips();
            }
        } else {
            SoDaoSearch.stopDetect();
        }
    },
    showTips: function(json) {
        if (!this.dependObj && this.dependId != "") {
            this.dependObj = $('#' + this.dependId);
        }
        var tbl = $('#tableList');
        if (!tbl.attr("id")) {
            var xy = this.dependObj.offset();
            tbl = $("<table>").attr("id", "tableList").attr("class", "g_t").css({
                display: "none",
                width: this.dependObj.outerWidth(),
                left: parseInt(xy.left),
                top: parseInt(xy.top) + this.dependObj.height(),
                position: "absolute",
                zIndex: sDialog.zIndex
            }).appendTo(document.body);
        } else {
            tbl.find("tr").remove();
        }

        if (json[1].length > 0) {
            var _tr, _td; ;
            for (var i = 0; i < json[1].length; i++) {
                _tr = $('<tr><td class="g_td1">' + json[1][i][0] + '</td><td class="g_td2"></td></tr>').attr("clicktext", json[1][i][0]).attr("index", i).bind("mouseover", function() {
                    $(this).css({ background: "#CFDDE3", color: "#333333" });
                    SoDaoSearch.rowIndex = parseInt($(this).attr("index"));
                }).bind("mouseout", function() {
                    $(this).css({ background: "#ffffff", color: "#333333" });
                    SoDaoSearch.rowIndex = -1;
                }).bind("click", function() {
                    SoDaoSearch.inputObj.val($(this).attr("clicktext"));
                    SoDaoSearch.prevKey = $(this).attr("clicktext");
                    var form = SoDaoSearch.inputObj.parents("form");
                    if (form.get(0)) {
                        form.get(0).submit();
                    }
                }).appendTo(tbl);
            }
            _tr = $('<tr></tr>').appendTo(tbl);
            _td = $('<td></td>').attr("class", "g_td1").appendTo(_tr);
            _td = $('<td></td>').attr("class", "g_td2").appendTo(_tr);
            $('<span style="cursor:pointer"><span/>').attr("class", "g_tc").html("关闭").bind("click", function() {
                SoDaoSearch.hiddenTips();
            }).appendTo(_td);
            tbl.show();
        }
        this.sending = false;
        this.rowIndex = -1;
    },
    hiddenTips: function() {
        var tbl = $('#tableList');
        if (tbl.attr("id")) { tbl.hide(); this.rowIndex = -1; };
    },
    keyDown: function(event) {
        var fo = document.activeElement;
        var self = SoDaoSearch;
        if (fo.id == self.inputId && fo.type == 'text') {
            if (self.rowIndex == -1) { self.tempKey = self.inputObj.val(); }
            var _pid;
            var tbl = $('#tableList');
            if (tbl.attr("id")) {
                event = window.event ? window.event : event;
                if (event.keyCode == 38) {
                    if (self.rowIndex > -1) {
                        _pid = self.rowIndex;
                        tbl.find("tr:eq(" + self.rowIndex + ")").mouseout();
                        self.rowIndex = _pid - 1;
                        if (self.rowIndex > -1) {
                            tbl.find("tr:eq(" + self.rowIndex + ")").mouseover();
                            self.inputObj.val(tbl.find("tr:eq(" + self.rowIndex + ")").attr("clicktext"));
                            self.prevKey = self.inputObj.val();
                        }
                        else {
                            self.inputObj.val(self.tempKey);
                            self.prevKey = self.tempKey;
                            self.rowIndex = -1;
                        }
                    }
                }
                else if (event.keyCode == 40) {
                    if (self.rowIndex == -1) { self.rowIndex = 0; }
                    else {
                        _pid = self.rowIndex;
                        tbl.find("tr:eq(" + self.rowIndex + ")").mouseout();
                        self.rowIndex = _pid + 1;
                    }
                    if (self.rowIndex < tbl.find("tr").length - 1) {
                        tbl.find("tr:eq(" + self.rowIndex + ")").mouseover();
                        self.inputObj.val(tbl.find("tr:eq(" + self.rowIndex + ")").attr("clicktext"));
                        self.prevKey = self.inputObj.val();
                    }
                    else {
                        self.inputObj.val(self.tempKey);
                        self.prevKey = self.tempKey;
                        self.rowIndex = -1;
                    }
                }
                else if (event.keyCode == 13) {
                    SoDaoSearch.hiddenTips();
                }
            }
        }
    }
}

//获取IP地址
function GetIPArea(ip, callback) {
    var ajax = {
        url: '/ajax/getIPArea', data: { ip: ip }, type: 'GET', dataType: 'json', cache: true,
        success: function(json, statusText) {
            if (json.returnType == 'normal') {
                if (json.returnInfo.status == "1") {
                    var name = "", code = "", address = "";
                    code = json.returnInfo.regionCode;
                    if (code == "") {
                        name = json.returnInfo.country;
                    }
                    else if (json.returnInfo.city == "") {
                        if (json.returnInfo.province != "") {
                            name += json.returnInfo.province;
                        }
                    }
                    if (json.returnInfo.city != "") {
                        name += json.returnInfo.city;
                    }
                    if (json.returnInfo.county != "") {
                        name += json.returnInfo.county;
                    }
                    if (json.returnInfo.unit != "") {
                        address = json.returnInfo.unit;
                    }
                    if (callback) { callback({ code: code, name: name, address: address }); }
                } else {
                    if (callback) { callback(null); }
                }
            } else {
                if (callback) { callback(null); }
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            if (callback) { callback(null); }
        }
    };
    $.ajax(ajax);
}

//在线图标显示
function OnlineDisplay() {
    var users = new Array();
    $("img.online-ico").each(function() {
        var user = $(this).attr("uid");
        if (user != "" && $.inArray(user, users) == -1) {
            users.push(user);
        }
    });
    if (users.length > 0) {
        var strs = "";
        for (var i = 0; i < users.length; i++) {
            if (i > 0) { strs += ","; }
            strs += users[i];
        }
        batchGetUserStatus(users, function(jsonData) {
            $.each(jsonData, function(i) {
                $("img[uid='" + jsonData[i].u + "']").each(function() { $(this).show(); });
            });
        });
    }
}

//邀请好友玩应用
function AppToFriends(appId, appName, users) {
    //load: function(url, title, width, height, modal, showCallBack, customerCloseCallback, dependId, align)
    sDialog.loading("载入中...");
    sDialog.load(
        "http://www.sodao.com/message/AppTofriends/" + appId + '?users=' + encodeURIComponent(users),
        "邀请好友参加“" + appName + "”",
        420,
        0,
        true,
        function() {
            sDialog.hideLoading();
        }
    );
    return false;
}

//寻找好友
function showInviteWin() {
    sDialog.loadIFrame("/home/profile/invitefriendwin", "寻找好友", 460, 370, true, null, "", true);
}

function closeInviteWin(winId) {
    sDialog.closef(winId);
    setTimeout(function() {
        alert("发送邀请成功");
        friendMayBe();
    }, 500);
}

function changeIfreamHeight(winId, heigth) {
    $('.boxy-content').attr('style', "text-align: center; display: block; width: 520px; height: 450px;");
    $('#sodaoIframe').attr('style', "visibility: visible; width: 520px; height: 450px;");
}


//可能认识的好友
function friendMayBe() {

    sDialog.loading("载入中...");
    sDialog.load(
                "/index/FriendMayBe",
                "可能认识的好友",
                620,
                0,
                true,
                function() {
                    sDialog.hideLoading();
                }
            );
    return false;
}

function showLimit(lid, user) {
    var url = '/user/LimitPage?limitId=' + lid + '&user=' + user;
    sDialog.loadIFrame(url, "", 390, 90, true);
    return false;
}

function checkLink(type, code, user, obj) {
    var url = '/user/CheckLink?code=' + code + '&user=' + user + '&type=' + type + '&rnd=' + Math.random();
    var linkhref = $(obj).attr("href");
    var ajax = {
        url: url,
        type: "POST",
        dataType: "html",
        success: function(data) {
            if (data > 0) {
                showLimit(data, user);
            }
            else {
                window.location.href = linkhref;
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            window.location.href = linkhref;
        }
    }

    $.ajax(ajax);
}

//登录窗口 return checkLogin('<%=this.Page.User.Identity.Name%>');
function checkLogin(visitUser) {
    if (visitUser == "" || visitUser == "undefined" || visitUser == null) {
        sDialog.loadIFrame("/User/LoginWindows?LoginWinFromUrl=" + encodeURIComponent(top.location.href), "搜道网 因为真实 所以精彩！赶快注册帐号登录，体验更多精彩乐趣！", 550, 230, true);
        return false;
    }
    return true;
}

//登录窗口 return checkLogin('<%=this.Page.User.Identity.Name%>');
function checkLogin(visitUser, title) {
    if (title == null || title == "" || title == "undefined") {
        title = "搜道网 因为真实 所以精彩！赶快注册帐号登录，体验更多精彩乐趣！"
    }

    if (visitUser == "" || visitUser == "undefined" || visitUser == null) {
        sDialog.loadIFrame("/User/LoginWindows?LoginWinFromUrl=" + encodeURIComponent(top.location.href), title, 550, 230, true);
        return false;
    }
    return true;
}

//登录窗口 return checkLogin('<%=this.Page.User.Identity.Name%>');
function checkLogin(visitUser, title, fromUrl) {
    if (fromUrl == null || fromUrl == "" || fromUrl == "undefined") {
        fromUrl = top.location.href;
    }

    if (title == null || title == "" || title == "undefined") {
        title = "搜道网 因为真实 所以精彩！赶快注册帐号登录，体验更多精彩乐趣！"
    }

    if (visitUser == "" || visitUser == "undefined" || visitUser == null) {
        sDialog.loadIFrame("/User/LoginWindows?LoginWinFromUrl=" + encodeURIComponent(fromUrl), title, 550, 230, true);
        return false;
    }
    return true;
}